﻿<%@ Page Title="" Language="C#" MasterPageFile="~/Main.Master" AutoEventWireup="true" CodeBehind="PageNotaFiscal.aspx.cs" Inherits="BonesoftWeb.Paginas.PageNotaFiscal" %>

<%@ Register Assembly="DevExpress.Web.v13.1, Version=13.1.5.0, Culture=neutral, PublicKeyToken=b88d1754d700e49a" Namespace="DevExpress.Web.ASPxPanel" TagPrefix="dx" %>

<%@ Register Assembly="DevExpress.Web.v13.1, Version=13.1.5.0, Culture=neutral, PublicKeyToken=b88d1754d700e49a" Namespace="DevExpress.Web.ASPxGridLookup" TagPrefix="dx" %>

<%@ Register Assembly="DevExpress.Web.v13.1, Version=13.1.5.0, Culture=neutral, PublicKeyToken=b88d1754d700e49a" Namespace="DevExpress.Web.ASPxEditors" TagPrefix="dx" %>

<%@ Register Assembly="DevExpress.Web.v13.1, Version=13.1.5.0, Culture=neutral, PublicKeyToken=b88d1754d700e49a" Namespace="DevExpress.Web.ASPxGridView" TagPrefix="dx" %>

<%@ MasterType VirtualPath="~/Main.Master" %>

<%@ Register Assembly="DevExpress.Web.v13.1, Version=13.1.5.0, Culture=neutral, PublicKeyToken=b88d1754d700e49a" Namespace="DevExpress.Web.ASPxPopupControl" TagPrefix="dx" %>

<asp:Content ID="Content2" ContentPlaceHolderID="cpMeio" runat="server">
    <asp:ObjectDataSource ID="odsModeloNotaFiscalDictionary" runat="server" SelectMethod="GetLista" TypeName="Business.Dicionary.ModeloNotaFiscalDicionary"></asp:ObjectDataSource>
    <asp:ObjectDataSource ID="odsNaturezaInterna" runat="server" SelectMethod="GetList" TypeName="Business.Entity.Fiscal.ClassesRelacionadas.NaturezaInternaRepository"></asp:ObjectDataSource>
    <asp:ObjectDataSource ID="odsCfop" runat="server" SelectMethod="GetList" TypeName="Business.Entity.Fiscal.ClassesRelacionadas.CfopRepository"></asp:ObjectDataSource>
    <asp:ObjectDataSource ID="odsUnidade" runat="server" SelectMethod="GetList" TypeName="Business.Entity.Estoque.Produto.ClassesRelacionadas.UnidadeRepository"></asp:ObjectDataSource>
    <asp:ObjectDataSource ID="odsCst" runat="server" SelectMethod="GetList" TypeName="Business.Entity.Sped.CSTRepositorio"></asp:ObjectDataSource>
    <asp:ObjectDataSource ID="odsNcm" runat="server" SelectMethod="GetList" TypeName="Business.Entity.Sped.NcmRepository"></asp:ObjectDataSource>
    <script src="../Scripts/jquery-2.0.3.js" type="text/javascript"></script>
    <script src="../Scripts/jquery-2.0.3-vsdoc.js" type="text/javascript"></script>
    <script src="../Scripts/jquery-2.0.3.min.js" type="text/javascript"></script>
    <script src="../Scripts/jquery.msgBox.js" type="text/javascript"></script>
    <script src="../Scripts/jquery.blockUI.js" type="text/javascript"></script>
    <script src="../Scripts/jquery.blockUI.min.js" type="text/javascript"></script>
    <script type="text/javascript">
        function SelecionarProduto() {
            
            $('#<%# cmdSelecionarProduto.ClientID %>_B').click();
        }
    </script>
    <table width="100%">
        <tr>
            <td>Informações da nota
                <!-- Tabela com os dados da nota fiscal. -->
                <table>
                    <tr>
                        <td>
                            <dx:ASPxLabel runat="server" Text="Identificador:" />
                        </td>
                        <td>
                            <dx:ASPxTextBox runat="server" Text="<%# Nota.Id %>" ID="txtIdNota" Enabled="False"></dx:ASPxTextBox>
                        </td>
                    </tr>
                    <tr>
                        <td>
                            <dx:ASPxLabel runat="server" Text="Número:" />
                        </td>
                        <td>
                            <dx:ASPxTextBox runat="server" ID="txtNumero"
                                Text="<%# Nota.Numero %>">
                            </dx:ASPxTextBox>
                        </td>
                        <td>
                            <dx:ASPxLabel runat="server" Text="Modelo" />
                        </td>
                        <td>
                            <dx:ASPxComboBox runat="server" ID="cboModelo"
                                ValueField="Valor" TextField="Descricao" DataSourceID="odsModeloNotaFiscalDictionary">
                                <Columns>
                                    <dx:ListBoxColumn FieldName="Descricao" Name="Descrição" />
                                </Columns>
                            </dx:ASPxComboBox>

                        </td>
                        <td>
                            <dx:ASPxLabel runat="server" Text="Série:" />
                        </td>
                        <td>
                            <dx:ASPxTextBox runat="server" ID="txtSerie" Text="<%# Nota.Serie %>" Width="50px" />
                        </td>
                    </tr>
                    <tr>
                        <td>
                            <dx:ASPxLabel runat="server" Text="Emissao:" />
                        </td>
                        <td>
                            <dx:ASPxDateEdit runat="server" ID="dtEmissao"
                                Date="<%# Nota.DataEmissao %>">
                            </dx:ASPxDateEdit>
                        </td>
                        <td>
                            <dx:ASPxLabel runat="server" Text="Entrada:" />
                        </td>
                        <td>
                            <dx:ASPxDateEdit ID="dtEntrada" runat="server"
                                Date="<%# Nota.DataEntrada %>">
                            </dx:ASPxDateEdit>
                        </td>
                    </tr>
                </table>

            </td>
        </tr>
        <tr>
            <td>
                <!-- Tabela com o campo para seleção da natureza interna. -->
                <table>
                    <tr>
                        <td>
                            <dx:ASPxLabel ID="ASPxLabel1" runat="server" Text="Natureza interna:">
                            </dx:ASPxLabel>
                        </td>
                        <td>

                            <dx:ASPxGridLookup ID="cboNaturezaInterna" runat="server" AutoGenerateColumns="False"
                                KeyFieldName="Id" DataSourceID="odsNaturezaInterna">
                                <GridViewProperties>
                                    <SettingsBehavior AllowFocusedRow="True" AllowSelectSingleRowOnly="True"></SettingsBehavior>
                                </GridViewProperties>
                                <Columns>
                                    <dx:GridViewDataTextColumn Caption="Descrição" FieldName="Descricao" VisibleIndex="1">
                                    </dx:GridViewDataTextColumn>
                                </Columns>
                            </dx:ASPxGridLookup>

                        </td>
                    </tr>
                </table>
            </td>
        </tr>
        <tr>
            <td>
                <div>Emissor</div>
                <!-- Emissor da nota fiscal. -->
                <table width="100%">
                    <tr>
                        <td colspan="2">
                            <table>
                                <tr>
                                    <td>
                                        <dx:ASPxLabel runat="server" Text="CNPJ:" />
                                    </td>
                                    <td>
                                        <dx:ASPxTextBox runat="server" ID="txtCnpjEmissor"
                                            Width="200px" Text="<%# Emissor.CpfCnpj %>">
                                        </dx:ASPxTextBox>
                                    </td>
                                    <td>
                                        <dx:ASPxButton runat="server" ID="cmdBuscaEmissor" Text="Buscar">
                                        </dx:ASPxButton>
                                    </td>
                                </tr>
                            </table>
                            <!-- Dados do emissor -->
                            <table>
                                <tr>
                                    <td>
                                        <dx:ASPxLabel runat="server" Text="Razão social:" />
                                    </td>
                                    <td>
                                        <dx:ASPxTextBox runat="server" ID="txtRazaoSocialEmissor"
                                            Width="300px" Text="<%# Emissor.Nome %>">
                                        </dx:ASPxTextBox>
                                    </td>
                                </tr>
                            </table>
                        </td>
                    </tr>
                    <tr>
                        <td colspan="2">
                            <table>
                                <tr>
                                    <td></td>
                                </tr>
                            </table>
                        </td>
                    </tr>
                </table>
            </td>
        </tr>
        <tr>
            <td>
                <!-- Transportadora -->
                <table width="100%">
                    <tr>
                        <td>
                            <div>Transportadora</div>
                            <table>
                                <tr>
                                    <td>
                                        <dx:ASPxLabel runat="server" Text="CNPJ:" />
                                    </td>
                                    <td>
                                        <dx:ASPxTextBox runat="server" ID="txtCnpjTransportadora"
                                            Width="200px" Text="<%# Transportadora.CpfCnpj %>">
                                        </dx:ASPxTextBox>
                                    </td>
                                    <td>
                                        <dx:ASPxButton runat="server" ID="cmdBuscarTransportadora"
                                            Text="Buscar" OnClick="cmdBuscarTransportadora_OnClick">
                                        </dx:ASPxButton>
                                    </td>
                                </tr>
                            </table>
                            <table>
                                <tr>
                                    <td>
                                        <dx:ASPxLabel runat="server" Text="Razão social:" />
                                    </td>
                                    <td>
                                        <dx:ASPxTextBox runat="server" ID="txtRazaoSocialTransportadora"
                                            Text="<%# Transportadora.Nome %>" Width="300px">
                                        </dx:ASPxTextBox>
                                    </td>
                                </tr>
                            </table>
                        </td>
                    </tr>
                </table>
            </td>
        </tr>
        <tr>
            <td>
                <!-- Produto -->
                <div>Produtos</div>
                <table width="100%">
                    <tr>
                        <td>

                            <dx:ASPxGridView ID="gridProdutoNotaFiscal" runat="server" Width="100%" AutoGenerateColumns="False"
                                OnRowDeleted="gridProdutoNotaFiscal_OnRowDeleted">
                                <Columns>

                                    <dx:GridViewDataTextColumn FieldName="Sequencia" VisibleIndex="1">
                                    </dx:GridViewDataTextColumn>
                                    <dx:GridViewDataTextColumn FieldName="Produto.Descricao" VisibleIndex="2">
                                    </dx:GridViewDataTextColumn>
                                    <dx:GridViewDataTextColumn FieldName="Quantidade" VisibleIndex="3">
                                    </dx:GridViewDataTextColumn>
                                    <dx:GridViewDataTextColumn FieldName="ValorUnitario" VisibleIndex="4">
                                    </dx:GridViewDataTextColumn>
                                    <dx:GridViewDataTextColumn FieldName="BaseIcms" VisibleIndex="5">
                                    </dx:GridViewDataTextColumn>
                                    <dx:GridViewDataTextColumn FieldName="ValorIcms" VisibleIndex="6">
                                    </dx:GridViewDataTextColumn>
                                    <dx:GridViewDataTextColumn FieldName="ValorIpi" VisibleIndex="7">
                                    </dx:GridViewDataTextColumn>
                                    <dx:GridViewCommandColumn VisibleIndex="0" Caption="">
                                        <EditButton Visible="True" Text="Alterar">
                                        </EditButton>
                                        <DeleteButton Visible="True" Text="Excluir">
                                        </DeleteButton>
                                    </dx:GridViewCommandColumn>
                                </Columns>
                            </dx:ASPxGridView>
                        </td>
                    </tr>
                    <tr>
                        <!-- Linha de adição de produtos. -->
                        <td>
                            <dx:ASPxPanel ID="ASPxPanel1" runat="server" Width="200px">
                                <PanelCollection>
                                    <dx:PanelContent runat="server">
                                        <table>
                                            <tr>
                                                <td>
                                                    <dx:ASPxLabel runat="server" Text="Sq." />
                                                </td>
                                                <td>
                                                    <dx:ASPxLabel runat="server" Text="Descrição" />
                                                </td>
                                            </tr>
                                            <tr>
                                                <td>
                                                    <dx:ASPxTextBox runat="server" ID="txtSequenciaProduto" Width="30px"></dx:ASPxTextBox>
                                                </td>
                                                <td>
                                                    <dx:ASPxTextBox runat="server" ID="txtIdProduto" Visible="False"></dx:ASPxTextBox>
                                                    <dx:ASPxTextBox runat="server" ID="txtDescricaoProduto" Width="300px"
                                                        Text="<%# ProdutoSelecionado.Descricao %>">
                                                    </dx:ASPxTextBox>
                                                </td>
                                                <td>
                                                    <dx:ASPxButton runat="server" ID="cmdBuscaProduto" Text="Buscar produto" OnClick="cmdBuscaProduto_OnClick">
                                                    </dx:ASPxButton>
                                                </td>
                                            </tr>
                                        </table>
                                    </dx:PanelContent>
                                </PanelCollection>
                            </dx:ASPxPanel>
                        </td>
                        <td>
                            <dx:ASPxPanel ID="pnlInformacoesCompraProduto" runat="server" Width="200px" >
                                <PanelCollection>
                                    <dx:PanelContent runat="server">
                                        <table align="center">

                                            <tr>

                                                <td>
                                                    <dx:ASPxLabel runat="server" Text="NCM" />
                                                </td>
                                                <td>
                                                    <dx:ASPxLabel runat="server" Text="CST" />
                                                </td>
                                                <td>
                                                    <dx:ASPxLabel runat="server" Text="CFOP" />
                                                </td>
                                                <td>
                                                    <dx:ASPxLabel runat="server" Text="Un." />
                                                </td>
                                                <td>
                                                    <dx:ASPxLabel runat="server" Text="Quantidade" />
                                                </td>
                                                <td>
                                                    <dx:ASPxLabel runat="server" Text="Valor" />
                                                </td>
                                                <td>
                                                    <dx:ASPxLabel runat="server" Text="ICMS" />
                                                </td>
                                                <td>
                                                    <dx:ASPxLabel runat="server" Text="IPI" />
                                                </td>
                                            </tr>

                                            <tr>

                                                <td>
                                                    <dx:ASPxGridLookup runat="server" ID="cboNcmProduto" Width="50px"
                                                        KeyFieldName="Id" AutoGenerateColumns="False" DataSourceID="odsNcm">
                                                        <GridViewProperties>
                                                            <SettingsBehavior AllowFocusedRow="True" AllowSelectSingleRowOnly="True"></SettingsBehavior>
                                                        </GridViewProperties>
                                                        <Columns>
                                                            <dx:GridViewDataTextColumn FieldName="Codigo" ShowInCustomizationForm="True" VisibleIndex="1">
                                                            </dx:GridViewDataTextColumn>
                                                        </Columns>
                                                    </dx:ASPxGridLookup>


                                                </td>
                                                <td>
                                                    <dx:ASPxGridLookup runat="server" ID="cboCstProduto" Width="50px" DataSourceID="odsCst">
                                                        <GridViewProperties>
                                                            <SettingsBehavior AllowFocusedRow="True" AllowSelectSingleRowOnly="True"></SettingsBehavior>
                                                        </GridViewProperties>
                                                        <Columns>
                                                            <dx:GridViewDataTextColumn FieldName="Codigo"></dx:GridViewDataTextColumn>
                                                        </Columns>
                                                    </dx:ASPxGridLookup>

                                                </td>
                                                <td>
                                                    <dx:ASPxGridLookup runat="server" ID="cboCfop" Width="50px" AutoGenerateColumns="False" DataSourceID="odsCfop">
                                                        <GridViewProperties>
                                                            <SettingsBehavior AllowFocusedRow="True" AllowSelectSingleRowOnly="True"></SettingsBehavior>
                                                        </GridViewProperties>
                                                        <Columns>
                                                            <dx:GridViewDataTextColumn FieldName="Cfop" ShowInCustomizationForm="True" VisibleIndex="1">
                                                            </dx:GridViewDataTextColumn>
                                                        </Columns>
                                                    </dx:ASPxGridLookup>

                                                </td>
                                                <td>
                                                    <dx:ASPxGridLookup runat="server" ID="cboUnidadeProduto" Width="50px" AutoGenerateColumns="False" DataSourceID="odsUnidade">
                                                        <GridViewProperties>
                                                            <SettingsBehavior AllowFocusedRow="True" AllowSelectSingleRowOnly="True"></SettingsBehavior>
                                                        </GridViewProperties>
                                                        <Columns>
                                                            <dx:GridViewDataTextColumn FieldName="Sigla" ShowInCustomizationForm="True" VisibleIndex="1">
                                                            </dx:GridViewDataTextColumn>
                                                        </Columns>
                                                    </dx:ASPxGridLookup>



                                                </td>
                                                <td>
                                                    <dx:ASPxTextBox runat="server" ID="txtQuantidadeProduto" Width="80px"></dx:ASPxTextBox>
                                                </td>
                                                <td>
                                                    <dx:ASPxTextBox runat="server" ID="txtValorProduto" Width="150px"></dx:ASPxTextBox>
                                                </td>
                                                <td>
                                                    <dx:ASPxTextBox runat="server" ID="txtIcmsProduto" Width="60px"></dx:ASPxTextBox>
                                                </td>
                                                <td>
                                                    <dx:ASPxTextBox runat="server" ID="txtIpiProduto" Width="60px"></dx:ASPxTextBox>
                                                </td>
                                                <td>
                                                    <dx:ASPxButton runat="server" ID="cmdAddProduto" Text="Adicionar"
                                                        OnClick="cmdAddProduto_OnClick">
                                                    </dx:ASPxButton>
                                                    <dx:ASPxButton runat="server" ID="cmdAlterarProduto" Text="Alterar"
                                                        
                                                        OnClick="cmdAlterarProduto_OnClick">
                                                    </dx:ASPxButton>
                                                </td>
                                                <td>
                                                    <dx:ASPxButton runat="server" ID="cmdLimparProduto" Text="Limpar"></dx:ASPxButton>
                                                </td>
                                            </tr>
                                        </table>
                                    </dx:PanelContent>
                                </PanelCollection>
                            </dx:ASPxPanel>

                        </td>
                    </tr>
                    <tr>
                        <td>
                            <dx:ASPxPopupControl ID="popProdutosEncontrados" runat="server" RenderMode="Lightweight">
                                <ContentCollection>
                                    <dx:PopupControlContentControl runat="server" SupportsDisabledAttribute="True">
                                        <div align="right">
                                            <dx:ASPxGridView ID="gridProduto"
                                                runat="server"
                                                AutoGenerateColumns="False"
                                                DataSourceID="odsProduto" KeyFieldName="Id"
                                                >
                                                <SettingsBehavior AllowFocusedRow="True"
                                                    AllowSelectByRowClick="True"></SettingsBehavior>
                                                
                                                <Columns>
                                                    <dx:GridViewDataTextColumn FieldName="Id" ShowInCustomizationForm="True" VisibleIndex="1">
                                                    </dx:GridViewDataTextColumn>
                                                    <dx:GridViewDataTextColumn FieldName="Descricao" ShowInCustomizationForm="True" VisibleIndex="2">
                                                    </dx:GridViewDataTextColumn>
                                                    <dx:GridViewDataTextColumn FieldName="Referencia" ShowInCustomizationForm="True" VisibleIndex="3">
                                                    </dx:GridViewDataTextColumn>
                                                    <dx:GridViewDataTextColumn FieldName="CodBarra" ShowInCustomizationForm="True" VisibleIndex="4">
                                                    </dx:GridViewDataTextColumn>
                                                    <dx:GridViewDataTextColumn FieldName="PrecoVenda" ShowInCustomizationForm="True" Visible="False" VisibleIndex="5">
                                                    </dx:GridViewDataTextColumn>
                                                    <dx:GridViewDataTextColumn FieldName="SaldoAtual" ReadOnly="True" ShowInCustomizationForm="True" Visible="False" VisibleIndex="6">
                                                    </dx:GridViewDataTextColumn>
                                                    <dx:GridViewDataCheckColumn FieldName="TemReceita" ShowInCustomizationForm="True" Visible="False" VisibleIndex="7">
                                                    </dx:GridViewDataCheckColumn>
                                                    <dx:GridViewDataDateColumn FieldName="UltimaCompra" ShowInCustomizationForm="True" VisibleIndex="8">
                                                    </dx:GridViewDataDateColumn>
                                                    <dx:GridViewDataTextColumn FieldName="Custo" ReadOnly="True" ShowInCustomizationForm="True" Visible="False" VisibleIndex="9">
                                                    </dx:GridViewDataTextColumn>
                                                    <dx:GridViewDataTextColumn FieldName="CustoMedio" ReadOnly="True" ShowInCustomizationForm="True" Visible="False" VisibleIndex="10">
                                                    </dx:GridViewDataTextColumn>
                                                    <dx:GridViewDataTextColumn FieldName="Lucro" ReadOnly="True" ShowInCustomizationForm="True" Visible="False" VisibleIndex="11">
                                                    </dx:GridViewDataTextColumn>
                                                    <dx:GridViewDataTextColumn FieldName="ValorPromocional" ShowInCustomizationForm="True" Visible="False" VisibleIndex="12">
                                                    </dx:GridViewDataTextColumn>
                                                    <dx:GridViewDataTextColumn FieldName="SaldoMinimo" ShowInCustomizationForm="True" Visible="False" VisibleIndex="13">
                                                    </dx:GridViewDataTextColumn>
                                                </Columns>
                                                <ClientSideEvents RowDblClick="function(e,s) { SelecionarProduto(); }"></ClientSideEvents>
                                            </dx:ASPxGridView>
                                            <asp:ObjectDataSource ID="odsProduto" runat="server" SelectMethod="GetEmptyList" TypeName="Business.Entity.Estoque.Produto.ProdutoRepository" DataObjectTypeName="Business.Entity.Estoque.Produto.Produto"></asp:ObjectDataSource>
                                            <dx:ASPxButton runat="server" Text="Selecionar" ID="cmdSelecionarProduto"
                                                OnClick="cmdSelecionarProduto_OnClick">
                                            </dx:ASPxButton>
                                        </div>
                                    </dx:PopupControlContentControl>
                                </ContentCollection>
                            </dx:ASPxPopupControl>
                        </td>
                </table>
            </td>
        </tr>

        <tr>
            <td>
                <!-- Valores da nota fiscal. -->
                <table>
                    <tr>
                        <td></td>
                        <td></td>
                    </tr>
                </table>
                <!-- Pagamento da nota fiscal. -->
                <table>
                    <tr>
                        <td>
                            <dx:ASPxGridView ID="gridPagamento" runat="server" AutoGenerateColumns="False">
                                <Columns>

                                    <dx:GridViewDataTextColumn FieldName="Id" Visible="False" VisibleIndex="1">
                                    </dx:GridViewDataTextColumn>
                                    <dx:GridViewDataDateColumn FieldName="Vencimento" VisibleIndex="2">
                                    </dx:GridViewDataDateColumn>
                                    <dx:GridViewDataTextColumn FieldName="Valor" VisibleIndex="3">
                                    </dx:GridViewDataTextColumn>
                                    <dx:GridViewCommandColumn VisibleIndex="0" Caption="">
                                        <DeleteButton Visible="True">
                                        </DeleteButton>
                                    </dx:GridViewCommandColumn>
                                </Columns>
                            </dx:ASPxGridView>
                        </td>
                    </tr>
                </table>
            </td>
        </tr>

    </table>
</asp:Content>
